package com.thread.bean;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class ChangeTextRunnable implements Runnable {

    private static final Lock lock = new ReentrantLock();
    private AccountBean accountBean;

    public ChangeTextRunnable(AccountBean accountBean) {
        this.accountBean = accountBean;
    }

    @Override
    public void run() {
//        if (!lock.tryLock()) {
//            return;
//        }

//        lock.lock();
        synchronized (accountBean){
            try {
                accountBean.setCout(accountBean.getCout() + 1);
                System.out.println(accountBean.getCout());
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
//            lock.unlock();
            }
        }

    }
}
